# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'categoryWindow.ui'
#
# Created: Thu May 31 22:53:56 2012
#      by: PyQt4 UI code generator 4.9.1
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui
from pl.edu.budgetanalizer.model.Product import Product
import pyodbc

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s

class Ui_MainWindow(QtGui.QDialog):
    
    listOfProducts = []
    
    def getProductsFromCategory(self,category):
        '''
        pobiera wszystkie produkty dla danej kategorii
        '''
        self.listOfProducts = []
        conn = pyodbc.connect(self.databaseDir)
        cur = conn.cursor()
        cur.execute("exec getProductsFromCategory ?",category.name)
        
        rows = cur.fetchall()
        for row in rows:
            product = Product(row[0],row[1],row[2],row[3],row[4],row[5])
            self.listOfProducts.append(product)
            print row[0]
            print row[1]
            print row[2]
            print row[3]
            print row[4]
            print row[5]

        
        
    def addProducts(self):
        '''
        dodaje produkty do wyswietlenia
        '''
        for product in self.listOfProducts:
            productHorizontalLayout = QtGui.QHBoxLayout()
            productHorizontalLayout.setObjectName(_fromUtf8("productHorizontalLayout"))
            productNameLabel = QtGui.QLabel(self.verticalLayoutWidget)
            productNameLabel.setObjectName(_fromUtf8("productNameLabel"))
            productHorizontalLayout.addWidget(productNameLabel)
            quantityNumberLabel = QtGui.QLabel(self.verticalLayoutWidget)
            quantityNumberLabel.setObjectName(_fromUtf8("quantityNumberLabel"))
            productHorizontalLayout.addWidget(quantityNumberLabel)
            measureQuantityLabel = QtGui.QLabel(self.verticalLayoutWidget)
            measureQuantityLabel.setObjectName(_fromUtf8("measureQuantityLabel"))
            productHorizontalLayout.addWidget(measureQuantityLabel)
            priceNumberLabel = QtGui.QLabel(self.verticalLayoutWidget)
            priceNumberLabel.setObjectName(_fromUtf8("priceNumberLabel"))
            productHorizontalLayout.addWidget(priceNumberLabel)
            measurePriceLabel = QtGui.QLabel(self.verticalLayoutWidget)
            measurePriceLabel.setObjectName(_fromUtf8("measurePriceLabel"))
            productHorizontalLayout.addWidget(measurePriceLabel)
            self.allLayout.addLayout(productHorizontalLayout)
            
            productNameLabel.setText(QtGui.QApplication.translate("MainWindow", QtCore.QString(product.name), None, QtGui.QApplication.UnicodeUTF8))
            quantityNumberLabel.setText(QtGui.QApplication.translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n"
    "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
    "<p align=\"right\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">"+QtCore.QString().setNum(product.quantity)+"</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
            measureQuantityLabel.setText(QtGui.QApplication.translate("MainWindow", QtCore.QString(product.measure), None, QtGui.QApplication.UnicodeUTF8))
            priceNumberLabel.setText(QtGui.QApplication.translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n"
    "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
    "<p align=\"right\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">"+QtCore.QString().setNum(product.price)+"</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
            measurePriceLabel.setText(QtGui.QApplication.translate("MainWindow", "zl", None, QtGui.QApplication.UnicodeUTF8))
                
        
    def setupUi(self, CategoryWidget,category,databaseDir):
        '''
        wygenerowane gui
        '''
        self.databaseDir = databaseDir
        CategoryWidget.resize(464, 372)
        self.getProductsFromCategory(category)

        self.categoryNameLabel = QtGui.QLabel(CategoryWidget)
        self.categoryNameLabel.setGeometry(QtCore.QRect(120, 10, 161, 31))
        self.categoryNameLabel.setObjectName(_fromUtf8("categoryNameLabel"))
        
        '''self.categoryNameLabel.setText(category.name)'''
        self.categoryNameLabel.setText(QtGui.QApplication.translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt;\">"+ QtCore.QString(category.name)+ "</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
       
        self.verticalLayoutWidget = QtGui.QWidget(CategoryWidget)
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(30, 50, 391, 251))
        self.verticalLayoutWidget.setObjectName(_fromUtf8("verticalLayoutWidget"))
        self.allLayout = QtGui.QVBoxLayout(self.verticalLayoutWidget)
        self.allLayout.setMargin(0)
        self.allLayout.setObjectName(_fromUtf8("allLayout")),
        
        self.addProducts()

        QtCore.QMetaObject.connectSlotsByName(CategoryWidget)

